package task

import (
	"GoPro/Server/msgProto"
	"GoPro/Server/mynet"
	"bytes"
	"encoding/binary"
	"fmt"
)

type PingRouter struct {
}

func (msg *PingRouter) PreHandler(req mynet.IRequest) {
	fmt.Println(string(req.GetData()))
}

func (msg *PingRouter) Handler(req mynet.IRequest) {
	dataBuf := bytes.NewBuffer([]byte{})
	header := msgProto.MsgHeader{
		MsgType: req.GetType(),
		MsgSize: int32(len(req.GetData())),
	}
	binary.Write(dataBuf, binary.BigEndian, header)
	binary.Write(dataBuf, binary.BigEndian, req.GetData())

	_, err := req.GetIConnection().GetWriter().Write(dataBuf.Bytes())
	if err != nil {
		fmt.Println(err)
		return
	}
	//fmt.Println(write)
}

func (msg *PingRouter) PostHandler(req mynet.IRequest) {
	fmt.Println(fmt.Sprintf("post ok msgType:%d", req.GetType()))
}
